import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;


public class MusteriSwing extends JFrame
{
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField textFieldEski;
	private JTextField textFieldYeni;

	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					MusteriSwing frame = new MusteriSwing();
					frame.setVisible(true);
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MusteriSwing()
	{
		final int saatUcreti = 3;

		setTitle("Elektrik Fatura Hesaplama Zamazingosu");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 408, 137);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		String[] comboBoxString = {"Yaz", "Bahar", "Kis", "Sonbahar"};
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
			new RowSpec[] {
				FormFactory.LINE_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,}));
		
		JLabel lblNewLabel = new JLabel("Sezon: ");
		contentPane.add(lblNewLabel, "2, 2, right, top");
		lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
		
		final JComboBox<String> comboBox = new JComboBox<String>(comboBoxString);
		contentPane.add(comboBox, "3, 2, 3, 1, fill, top");
		comboBox.setMaximumRowCount(4);
		comboBox.setToolTipText("Sezon seciniz.");

		JLabel lblEskiSayacDegeri = new JLabel("Eski Sayac Degeri: ");
		contentPane.add(lblEskiSayacDegeri, "2, 4, right, default");
		
		textFieldEski = new JTextField();
		contentPane.add(textFieldEski, "3, 4");
		textFieldEski.setToolTipText("Eski sayac degerini giriniz.");
		textFieldEski.setColumns(10);

		JLabel lblYeniSayacDegeri = new JLabel("  Yeni Sayac Degeri: ");
		contentPane.add(lblYeniSayacDegeri, "4, 4, right, default");
		
		textFieldYeni = new JTextField();
		contentPane.add(textFieldYeni, "5, 4");
		textFieldYeni.setToolTipText("Yeni sayac degerini giriniz.");
		textFieldYeni.setColumns(10);
		
		final JLabel lblFatura = new JLabel("Fatura: ");
		contentPane.add(lblFatura, "5, 6, left, default");
		
		JButton btnHesapla = new JButton("Hesapla");
		contentPane.add(btnHesapla, "2, 6");
		btnHesapla.addActionListener(new ActionListener(){
			 
			public void actionPerformed(ActionEvent e) {
				int delta = Integer.parseInt(textFieldYeni.getText().trim()) - Integer.parseInt(textFieldEski.getText().trim());
				switch(comboBox.getSelectedIndex())
				{
				case 0:
					lblFatura.setText("Fatura: " + String.valueOf((double)((delta * saatUcreti) * 90.0 / 100.0)));
					break;
					
				case 1:
					lblFatura.setText("Fatura: " + String.valueOf((double)((delta * saatUcreti) * 99.0 / 100.0)));
					break;
					
				case 2:
					lblFatura.setText("Fatura: " + String.valueOf((double)((delta * saatUcreti))));
					break;

				case 3:
					lblFatura.setText("Fatura: " + String.valueOf((double)((delta * saatUcreti) * 93.0 / 100.0)));
					break;
				}
				
			}
        });
	}
}
